<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of pickup_model
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Admin_pickup_model extends CI_Model {

    //put your code here

    function __construct() {
        parent::__construct();
        log_message('debug', 'Model Initialized');
    }

//-- Get country Result()
    function populate_country() {
        $sql = "Select * from country where status=51";
        $query = $this->db->query($sql);
        $result = $query->result();
        return $result;
    }

//-- Get Car Make Result (Subha- 29/07/2012)
    function get_car_makes() {
        $sql = "Select * from make where status=51";
        $query = $this->db->query($sql);
        $result = $query->result();
        return $result;
    }

//--Get Listing of Pickup Codes --Subha(30/07/2012)//
    function get_pickup_codes() {
        $sql = "select * from pickup where status = 51 and slno=0 and code <> 0 order by description";
        $query = $this->db->query($sql);
        $result = $query->result();
        if ($result) {
            return $result;
        } else {
            return FALSE;
        }
    }

//--Get Max Pickup Code and SLno--//
    function get_max_pickup_no($para, $code) {
        if ($para == 'CODE' && $code == 0) {
            $sql = "select max(code) as no from pickup where code <> 0 and slno = 0";
            $query = $this->db->query($sql);
            $row = $query->row();
            return intval($row->no) + 1;
        }
        if ($para == 'SLNO' && $code <> 0) {
            $sql = "select max(slno) as no from pickup where code = $code and slno <> 0";
            $query = $this->db->query($sql);
            $row = $query->row();
            return intval($row->no) + 1;
        }
    }

//--Insert Pickup Code (Subha 30/07/2012)--/    
    function pickup_code_insert($post_data) {
        if ($post_data) {
            $this->db->insert('pickup', $post_data);
        }
    }
//--Insert Pickup Detail (Subha 30/07/2012)--/    
    function pickup_detail_insert($post_data) {
        if ($post_data) {
            $this->db->insert('pickup', $post_data);
        }
    }
//--Delete Pickup Code (Subha 30/07/2012)--/    
    function pickup_code_delete($code) {
        if ($code) {
            $sql = "delete from pickup where code = $code";
            $this->db->query($sql);
        }
    }
//--Delete Pickup Code (Subha 30/07/2012)--/    
    function pickup_description_delete($code,$slno){
        if ($code) {
            $sql = "delete from pickup where code = $code and slno = $slno" ;
            $this->db->query($sql);
        }
    }
//--Update Pickup Code (Subha 30/07/2012)--/    
    function pickup_code_update($post_data) {
        if ($post_data) {
		$des=$post_data['description'];
		$code=$post_data['code'];
			$sql="update pickup set description='$des' where code=$code and slno=0";
			$this->db->query($sql);            
        }
    }
//--Update Pickup Code (Subha 30/07/2012)--/    
    function pickup_description_update($post_data) {
        if ($post_data) {
            $this->db->where('code', $post_data['code']);
            $this->db->where('slno', $post_data['slno']);
            $this->db->update('pickup', $post_data);
        }
    }

//--Get Pickup Result (Subha/29/07/2012)    
    function get_pickup($code) {
        $sql = "select * from pickup where slno != 0 and code = $code and status = 51 order by description";
        $query = $this->db->query($sql);
        $result = $query->result();
        return $result;
    }

//--Get Pickup Information -->
    function get_pickup_info($code=0, $slno=0) {
        $sql = "select * from pickup where code = $code and slno = $slno";
        $query = $this->db->query($sql);
        $row = $query->row();
        return $row;
    }

    
//-- Populate Year
//-- date('Y',now())    
    function populate_year($pn='P', $no=5, $start) {
        $result = array();
        $y = $start;
        $i = 0;
        if ($pn == 'N') {
            for ($i = 0; $i <= $no; $i++) {
                $result[$i] = $y + $i;
            }
        } else {
            for ($i = 0; $i <= $no; $i++) {
                $result[$i] = $y - $i;
            }
        }
        return $result;
    }

}

?>
